/**
 * @author Maximilian Csuk
 * @author Bernhard Denner
 * @author Konrad Paumann
 */

import java.util.Random;

public class IntBinTreeDeleter implements Runnable {
	private BinTree<MyInteger> t;
	private int decCount; 		// number of times node was decremented
	private int deleteCount; 	// number of times node was deleted
	private int notfoundCount;	// number of times node was not found
	private OutputHandler out;
	private int id;
	
	public IntBinTreeDeleter(BinTree<MyInteger> t, OutputHandler o, int id) {
		this.t = t;
		this.decCount = this.deleteCount = this.notfoundCount = 0;
		out = o;
		this.id = id;
	}
	/**
	 * Deletes 10000 MyIntegers in the tree
	 * and then writes statistics of the operation to the output
	 */
	public void run() {
		for(int i = 0;i < 10000;i++) {
			int k = new Random().nextInt(100);
			byte r = t.delete(new MyInteger(k));

			switch (r) {
			case 0: notfoundCount++; break;
			case 1: decCount++; break;
			case 2: deleteCount++; break;
			}
		}
		
		out.print("Deleter " + id + " finished... " +
					deleteCount + " nodes deleted, " +
					decCount + " nodes decremented, " +
					notfoundCount + " nodes not found");

	}
}

